// CDQ
// https://www.luogu.com.cn/problem/P3157
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
using namespace std;
using ll = long long;
using T = int;
T rad(); // quick read
const int inf = 0x3f3f3f3f;
#define rf(i, n) for (int i = 1; i <= (n); ++i)
const int max_size = 5 + 1e5;
const int maxn = 5 + 1e5;

int n, m;
struct Node {
    int pos, val, tim; // 位置，数值，持续时间
    bool operator<(const Node &r) const { return tim != r.tim ? tim > r.tim : pos < r.pos; }
} a[maxn];

struct segtree {
    int val[maxn << 2];
    void clear() { memset(val, 0, sizeof(val)); }
    void maintain(int u) { val[u] = val[u << 1] + val[u << 1 | 1]; }
    void update(int u, int l, int r, int i, int x) {
        if (l == r) {
            val[u] += x;
            return;
        }

        int mid = l + r >> 1;
        if (i <= mid)
            update(u << 1, l, mid, i, x);
        else
            update(u << 1 | 1, mid + 1, r, i, x);
        maintain(u);
    }

    int ask(int u, int l, int r, int s, int t) {
        if (s <= l && r <= t) return val[u];
        int mid = l + r >> 1;
        if (t <= mid) return ask(u << 1, l, mid, s, t);
        if (s > mid) return ask(u << 1 | 1, mid + 1, r, s, t);
        return ask(u << 1, l, mid, s, t) + ask(u << 1 | 1, mid + 1, r, s, t);
    }
} sg;

ll f[maxn]; // f[i] 表示在第 i 个版本，逆序对的减少数量
int id[maxn];
bool cmp(int i, int j) { return a[i].pos < a[j].pos; }

void cdq(int l, int r) {
    if (l == r) return;
    int mid = l + r >> 1;
    cdq(l, mid);
    // printf("%d %d\n", l, r);

    for (int i = l; i <= r; ++i) id[i] = i;
    sort(id + l, id + r + 1, cmp);
    for (int j = l; j <= r; ++j) { // 从左到右，找大的
        int i = id[j];
        if (i <= mid) // 左边维护数据，版本更大
            sg.update(1, 1, n, a[i].val, 1);
        else // 右边统计，对于逆序对 (i, j)，删除 j 将影响所有 i 的版本大于 j 的
            f[a[i].tim] += sg.ask(1, 1, n, a[i].val, n);
    }
    for (int j = l; j <= r; ++j) {
        int i = id[j]; // 清空
        if (i <= mid) sg.update(1, 1, n, a[i].val, -1);
    }
    for (int j = r; j >= l; --j) { // 从右到左，找小的
        int i = id[j];
        if (i <= mid) // 左边维护数据，版本更大
            sg.update(1, 1, n, a[i].val, 1);
        else // 右边统计
            f[a[i].tim] += sg.ask(1, 1, n, 1, a[i].val);
    }
    for (int j = l; j <= r; ++j) {
        int i = id[j]; // 清空
        if (i <= mid) sg.update(1, 1, n, a[i].val, -1);
    }
    cdq(mid + 1, r);
}

int main() {
    n = rad(), m = rad();
    map<int, int> val_to_id;
    ll ans = 0;
    rf(i, n) { a[i].pos = i, a[i].val = rad(), a[i].tim = n + 1, val_to_id[a[i].val] = i; }
    rf(i, m) a[val_to_id[rad()]].tim = i;

    sg.clear();
    rf(i, n) {
        ans += sg.ask(1, 1, n, a[i].val, n);
        sg.update(1, 1, n, a[i].val, 1);
    }

    sg.clear();
    sort(a + 1, a + 1 + n);
    cdq(1, n);
    for (int i = 1; i <= m; ++i) {
        printf("%lld\n", ans);
        ans -= f[i];
    }
    // rf(i, n) printf("%d %d || ", a[i].val, a[i].tim);
    // puts("");
    // for (int i = 0; i <= n; ++i) printf("%d ", f[i]);
    // puts("");
}

T rad() {
    T back = 0;
    int ch = 0, posi = 0;
    for (; ch < '0' || ch > '9'; ch = getchar())
        posi = ch ^ '-';
    for (; ch >= '0' && ch <= '9'; ch = getchar())
        back = (back << 1) + (back << 3) + (ch & 0xf);
    return posi ? back : -back;
}